package com.剑指offer;

public class _44翻转单词
{

    public static void main(String[] args)
    {
        int []a = {1,2};

        System.out.println(ReverseSentence("i am mazhao"));
    }

    public static String ReverseSentence(String str)
    {
        if (str.length() == 0 || str.length() == 1 || str.trim().equals(""))
        {
            return str;
        }

        String[] strs = str.split(" ");
        StringBuilder sb = new StringBuilder();
        int length = strs.length;
        for (int i = length - 1; i >= 0; i--)
        {
            if (i == 0)
            {
                sb.append(strs[i]);
            }
            else
            {
                sb.append(strs[i]);
                sb.append(" ");
            }
        }
        String result = sb.toString();
        return result;
    }
}
